var common = require('../controller/commonController.js');

var OuthouseModel = require("../model/OuthouseModel.js");
var setting = require("../database/setting.js");
var Mysql = require("node-mysql-promise");

class OuthouseController{
	constructor(){
		this.outhouseModel = new OuthouseModel();
		this.connection =  Mysql.createConnection(setting);
	}

	//获取所有出库单数据
	getOuthouseOrderAll(callback){
		var sqlStr = "";
		sqlStr = "SELECT * from tb_outhouse order by outhouse_date,outhouse_name";
		this.outhouseModel.findAllOrderByDate(this.connection,sqlStr).then((data) => {
			data.forEach((value)=>{
		   	   value.outhouse_date = common.timeChange(value.outhouse_date);//处理日期类型
		    });
		    callback(data);
		})
	}

	saveDealData(data,callback){
		this.outhouseModel.addNewOutTable(this.connection,data).then((value)=>{
			callback('success');
		});
	}

}

module.exports = OuthouseController;